<?php
// +---------------------------------------------------------------------+
// | OneBase    | [ WE CAN DO IT JUST THINK ]                            |
// +---------------------------------------------------------------------+
// | Licensed   | http://www.apache.org/licenses/LICENSE-2.0 )           |
// +---------------------------------------------------------------------+
// | Author     | Bigotry <3162875@qq.com>                               |
// +---------------------------------------------------------------------+
// | Repository | https://gitee.com/Bigotry/OneBase                      |
// +---------------------------------------------------------------------+

namespace app\common\logic;

/**
 * 文章逻辑
 */
class Forjob extends LogicBase
{
    
    /**
     * 文章分类编辑
     */
    public function forJobEdit($data = [])
    {
        
        $validate_result = $this->validateForjob->scene('edit')->check($data);
        
        if (!$validate_result) {
            
            return [RESULT_ERROR, $this->validateForjob->getError()];
        }
        
        $url = url('toEmploy');
        
        $handle_text = empty($data['id']) ? '新增' : '编辑';
        
        if($handle_text == '新增'){
            
            $data['created_at'] = time();
        }
        
        $data['updated_at'] = time();
        
        $result = $this->modelCustomer->setInfo($data);
        
        $result && action_log($handle_text, '文章分类' . $handle_text . '，name：' . $data['jobs_name']);
        
        return $result ? [RESULT_SUCCESS, '操作成功', $url] : [RESULT_ERROR, $this->modelForJob->getError()];
    }
    
    /**
     * 获取文章列表
     */
    public function getJobsList($where = [], $field = '*', $order = '')
    {
        
        $where[DATA_STATUS_NAME] = ['neq', DATA_DELETE];
        
        return $this->modelForJob->getList($where, $field, $order, DB_LIST_ROWS);
    }
    
    
    
    
    /**
     * 获取分类信息
     */
    public function getJobsInfo($where = [], $field = true)
    {
        
        return $this->modelForJob->getInfo($where, $field);
    }
    
 
    /**
     * 文章删除
     */
    public function articleDel($where = [])
    {
        
        $result = $this->modelForJob->deleteInfo($where);
        
        $result && action_log('删除', '文章删除，where：' . http_build_query($where));
        
        return $result ? [RESULT_SUCCESS, '文章删除成功'] : [RESULT_ERROR, $this->modelForJob->getError()];
    }
}
